/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.gitee.jmash.websocket.model;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.gitee.jmash.core.utils.JsonbUtil;
import jakarta.websocket.EncodeException;
import jakarta.websocket.Encoder;
import jakarta.websocket.EndpointConfig;

/**
 * Message Encoder.
 *
 * @author Juneau
 */
public class MessageEncoder implements Encoder.Text<Message> {
  
  private static Log log = LogFactory.getLog(MessageEncoder.class);

  @Override
  public String encode(Message message) throws EncodeException {
    String json=JsonbUtil.toJson(message);
    return json;
  }

  @Override
  public void init(EndpointConfig ec) {
    log.info("Initializing message encoder");
  }

  @Override
  public void destroy() {
    log.info("Destroying encoder...");
  }

}
